# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/surnia_defconfig

pkgname=linux-motorola-surnia
pkgver=3.10.49
pkgrel=3
pkgdesc="Motorola Moto E (2nd Gen) kernel fork"
arch="armhf"
_carch="arm"
_flavor="motorola-surnia"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev dtbtool gcc6 xz"

# Compiler: GCC 6 (doesn't compile with newer versions)
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_motorola_msm8916"
_commit="4c864820053bb70e21cf1e9764baefefd4d2f6b1"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
	$_config
	gcc7-give-up-on-ilog2-const-optimizations.patch
	gcc10-extern_YYLOC_global_declaration.patch
"
builddir="$srcdir/$_repository-$_commit"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"

	# Generate master DTB (deviceinfo_bootimg_qcdt)
	dtbTool -s 2048 -p "scripts/dtc/" -o "arch/arm/boot/dt.img" "arch/arm/boot/"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"

	# Master DTB (deviceinfo_bootimg_qcdt)
	install -Dm644 "$builddir/arch/arm/boot/dt.img" \
		"$pkgdir/boot/dt.img"
}

sha512sums="28e70a5af0df65b85c257c4ca455553d38b17dad8d141876854c5a38502114638c8e59440cffcf81c278a6836e39ec0f63ed35dad825c49a8c3f299de7617b80  linux-motorola-surnia-4c864820053bb70e21cf1e9764baefefd4d2f6b1.tar.gz
162855d4c8d738e9876101893c40a6c4c85e4b6123646402c70a2a6a72d754cd6eccd6bf9e9ca5baa7b5f0353640190be38f4768933c2f2362519d739b898218  config-motorola-surnia.armhf
77eba606a71eafb36c32e9c5fe5e77f5e4746caac292440d9fb720763d766074a964db1c12bc76fe583c5d1a5c864219c59941f5e53adad182dbc70bf2bc14a7  gcc7-give-up-on-ilog2-const-optimizations.patch
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch"
